{{extend "test_layout.html"}}

{{block sub_menu}}
{{sub_menu(menu_items, 'test', 'testplan')}}
{{end}}

{{block content_main}}
{{use "jquery", css_only=True}}
{{use "facebox"}}
{{use "jqutils", ajaxForm=True}}
{{link "tforms.css"}}
{{include "inc_jqmultiselect.html"}}
<style type="text/css">
<!--
#comments {list-style:none;}
#comments li {list-style:none;display:block;padding:10px 0 10px 0;}
div.comment-index {float:left; width: 30px; font-size: 200%;margin-right:10px;}
div.comment-body {float:left; width: 500px;}
#comments .odd {background-color:#eff3f9; padding: 5px;}
#comments .comment-title {margin:5px 0px 2px 35px; padding:2px; color:#999;}
#comments .comment-footer {margin:5px 0px 2px 35px; padding:2px; color:#999;}
#comments .approve-result {font-size:200%;font-weight:bold;}
-->
</style>

<div class="content">
    <div class="box col_14">
        <h2>{{=object.title}}测试计划</h2>
        <div class="box-body">
            {{<< view}}
            <div class="box-bottom">
                {{if (object.approve == '0' and ((object.task and object.task.task_sys.users.has(request.user)) or (object.submitter.id == request.user.id))) or has_permission(request.user, 'TestEnvApprove'):}}
                    <a class="btn btn-green" href="/tests/plans/edit/{{=object.id}}">编辑</a>
                {{pass}}
                {{if object.approve == '0' and ((object.task and object.task.task_sys.users.has(request.user)) or (object.submitter.id == request.user.id)):}}
                    <a class="btn btn-blue" href="/tests/plans/delete/{{=object.id}}">删除</a>
                {{pass}}
                {{if object.approve == '1' and object.status not in ('F', 'C') and request.user.department=='3':}}
                    <a class="btn btn-green" href="/tests/plans/execute/{{=object.id}}">执行</a>
                {{pass}}
            </div>
        </div>
    </div>
    <div class="box box-panel col_14">
        <h2>审批记录</h2>
        <div class="box-body">
            <ul id="comments"></ul>
        </div>
    </div>
    <div class="box box-panel col_14">
        <h2>测试计划审批</h2>
        {{if has_permission(request.user, 'TestPlanApprove') and object.approve in ('0', '5'):}}
        <div class="box-body">
            {{<< plan_approve_form}}
        </div>
        {{pass}}
        {{if has_permission(request.user, 'TestEnvApprove') and object.approve in ('0', '4'):}}
        <div class="box-body">
            {{<< env_approve_form}}
        </div>
        {{pass}}
    </div>
</div>
<script type="text/html" id="commentTemplate">
    <li>
        <div class="clearfix">
            <div class="comment-index">${index}</div>
            <div class="comment-title">${type}</div>
            <div class="comment-body"><span class="approve-result">${approve}</span>${comment}</div>
        </div>
        <div class="clear"></div>
        <div class="comment-footer">
            由 <font color="blue"><b>${approver}</b></font> 写于 ${approve_date}
        </div>
    </li>
</script>

<script type="text/javascript">
var load_comments = function(){
    $.ajax({
        type: "POST",
        url: "/tests/plans/comments/{{=object.id}}",
        success: function(data){
            var ul = $('#comments');
            $.each(data, function(index, value){
                var comment = template($('#commentTemplate').html(), value).appendTo(ul);
            });
        }
    });
}
$(function(){
    load_comments();
});

</script>
{{end}}
